package cn.ucloud.usms;

import org.apache.commons.lang.StringUtils;
import org.apache.http.client.methods.HttpGet;

import java.util.ArrayList;
import java.util.List;

public class TestSMS {
    private Class<? extends BaseResponseResult> resultClass;

    public static void main(String[] args) {
        try {
            List<String> phoneNumbers = new ArrayList<>();
            //get 方式一次最多200个号码
            phoneNumbers.add("13666067037");
            BaseRequestParam param = new SendUSMSMessageParam(phoneNumbers,"UTB190724A950DC");
            param.setAction("SendUSMSMessage");
            param.setPublicKey("+CyVLxLkDjf4cJ8PPin0OLQEXCA7Sv46FGGS49vXbcGmbmWmrKNdm4OaFFc=");
            Account account = new Account("z3EEZ5Ycs9hVvjMva7Dz3pLQvZJzjUGiZ1YmjCNwaXGEWo3dR98koL+mEkcsbYYS","+CyVLxLkDjf4cJ8PPin0OLQEXCA7Sv46FGGS49vXbcGmbmWmrKNdm4OaFFc=");
            List<Param> paramList = ObjectToParam.objectToParams(param);
            // 获取签名字符串
            String signature = Signature.getSignature(paramList, account);

            // url编码
            Signature.urlEncodeParams(paramList);

            // 构造url参数
            StringBuilder builder = new StringBuilder();
            for (Param param1 : paramList) {
                if (StringUtils.isBlank(param1.getParamKey())){
                    continue;
                }
                builder.append(param1.getParamKey() + "=" + param1.getParamValue() + "&");
            }
            // 设置签名
            builder.append("Signature" + "=" + signature);

            String urlPara = builder.toString();

            String apiUrl = "https://api.ucloud.cn";

            final HttpGet get = new HttpGet(apiUrl + "?" + urlPara);

            Http http = new Http(SendUSMSMessageResult.class);

            BaseResponseResult result = http.doHttp(get, null,false);


            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
